#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int takeAttendance(vector<int>& records) {
        int left = 0;
        int right = records.size() - 1;
        int mid = 0;
        while (left < right)
        {
            mid = left + (right - left) / 2;
            if (records[mid] == mid)
                left = mid + 1;
            else
                right = mid;
        }
        if (left == records[left])
            return left + 1;

        return left;
    }
};